import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2023-03-08
 * Time: 20:56
 */

@SuppressWarnings({"all"})
public class MapMethod {
    public static void main(String[] args) {
        //map接口的常用方法
        Map map = new HashMap();
        map.put("邓超",new Book("",100));
        map.put("邓超","孙俪"); //替换
        map.put("王宝强","马蓉");
        map.put("宋喆","马蓉");
        map.put("刘令博",null);
        map.put(null,"刘亦菲");
        map.put("鹿晗","关晓彤");

        System.out.println("map=" + map);
        //remove 根据k删除
        map.remove(null);
        System.out.println("map=" + map);

        //根据k来获取值 对象的形式返回
        System.out.println(map.get("鹿晗"));

        //size 返回多少对元素
        System.out.println("k-v="+map.size());

        //isEmpty 判断是否为空
        System.out.println(map.isEmpty());

        //清空键值对 clear
        //map.clear();
        //System.out.println("map=" + map);

        //查看键是否存在 containsKey
        System.out.println(map.containsKey("hsp"));


    }
}


class Book{
    private String name;
    private int price;

    public Book(String name, int price) {
        this.name = name;
        this.price = price;
    }
}